package id.co.shuba.spamobile.data;

import id.co.shuba.spamobile.model.CommunicationInfo;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class CommunicationDB extends BaseDB {		
	public static final String TYPE_UPLOAD = "Upload";
	public static final String TYPE_DOWNLOAD = "Download";
	
	public CommunicationDB(DatabaseHandler db) {
		super(db);
	}
			
	public void add(CommunicationInfo info, String date) {
		SQLiteDatabase db = _db.getWritableDatabase();
		add(db, info, date);
	}		
	
	public static void add(SQLiteDatabase db, CommunicationInfo info, String date) {
		ContentValues values = createValues(info, date);		
		db.insert("TBL_COMMUNICATION", null, values);
	}
	
	public Cursor getList() {
		SQLiteDatabase db = _db.getReadableDatabase();
		return db.rawQuery("SELECT * FROM TBL_COMMUNICATION", null);
	}
	
	private static ContentValues createValues(CommunicationInfo info, String date) {
		ContentValues values = new ContentValues();
		
		values.put("COMM_TYPE", info.getType());
		values.put("COMM_DATA", info.getData());
		values.put("COMM_DATE", date);
		values.put("PACKAGE_SIZE", info.getPackageSize());
		values.put("TOTAL_ROW", info.getTotalRow());
		values.put("DESCRIPTION", info.getDescription());
		
		return values;
	}
}
